package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.common.utils.DateUtils;
import com.lxmes.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.CcCaigouDetail;
import com.lxmes.business.service.ICcCaigouDetailService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 采购详情Controller
 * 
 * @author 张志煜
 * @date 2022-06-11
 */
@Api(tags="采购单据详情管理")
@RestController
@RequestMapping("/business/caigouDetail")
public class CcCaigouDetailController extends BaseController
{
    @Autowired
    private ICcCaigouDetailService ccCaigouDetailService;

    /**
     * 查询采购详情列表
     */
    @ApiOperation("单据详情列表")
   // @PreAuthorize("@ss.hasPermi('business:caigouDetail:listInfo')")
    @GetMapping("/list")
    public TableDataInfo list(CcCaigouDetail ccCaigouDetail)
    {
        startPage();
        List<CcCaigouDetail> list = ccCaigouDetailService.selectCcCaigouDetailList(ccCaigouDetail);
        return getDataTable(list);
    }
    /**
     * 查询采购详情列表
     */
    @GetMapping("/getListAll")
    public AjaxResult getListAll(CcCaigouDetail ccCaigouDetail)
    {
        if(StringUtils.isNull(ccCaigouDetail.getCaigouDate())&& StringUtils.isNull(ccCaigouDetail.getCaigouDanhao())){
            ccCaigouDetail.setCaigouDate(DateUtils.parseDate(DateUtils.getDate()));
        }
        ccCaigouDetail.setIsRk(1L);
        List<CcCaigouDetail> list = ccCaigouDetailService.selectCcCaigouDetailList(ccCaigouDetail);
        return AjaxResult.success(list);
    }

    /**
     * 导出采购详情列表
     */
    @PreAuthorize("@ss.hasPermi('business:caigouDetail:export')")
    @Log(title = "采购详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcCaigouDetail ccCaigouDetail)
    {
        List<CcCaigouDetail> list = ccCaigouDetailService.selectCcCaigouDetailList(ccCaigouDetail);
        ExcelUtil<CcCaigouDetail> util = new ExcelUtil<CcCaigouDetail>(CcCaigouDetail.class);
        util.exportExcel(response, list, "采购详情数据");
    }

    /**
     * 获取采购详情详细信息
     */
   // @PreAuthorize("@ss.hasPermi('business:caigouDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccCaigouDetailService.selectCcCaigouDetailById(id));
    }

    /**
     * 新增采购详情
     */
    @PreAuthorize("@ss.hasPermi('business:caigouDetail:add')")
    @Log(title = "采购详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcCaigouDetail ccCaigouDetail)
    {
        return toAjax(ccCaigouDetailService.insertCcCaigouDetail(ccCaigouDetail));
    }
    /**
     * 添加采购物料明细
     */
    @GetMapping("/addCaigoItemInfo/{ids}")
    public AjaxResult addCaigoItemInfo(@PathVariable Long[] ids)
    {
        List<CcCaigouDetail> list = ccCaigouDetailService.addCaigoItemInfo(ids);
        return AjaxResult.success(list);
    }

    /**
     * 修改采购详情
     */
    @PreAuthorize("@ss.hasPermi('business:caigouDetail:edit')")
    @Log(title = "采购详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcCaigouDetail ccCaigouDetail)
    {
        return toAjax(ccCaigouDetailService.updateCcCaigouDetail(ccCaigouDetail));
    }

    /**
     * 删除采购详情
     */
    @PreAuthorize("@ss.hasPermi('business:caigouDetail:remove')")
    @Log(title = "采购详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccCaigouDetailService.deleteCcCaigouDetailByIds(ids));
    }
}
